<Query Kind="Statements">
  <Namespace>System.Windows</Namespace>
  <Namespace>System.Windows.Forms</Namespace>
</Query>

Publisher _publisher = new Publisher();
Subscriber _subscriber = new Subscriber();
_publisher.SampleEvent += _subscriber.Receive;

Subscriber _weak_event = new Subscriber();
BaseWeakEventManager.AddListener(_publisher, _weak_event);

_publisher.RaiseEvent();

public class Publisher
{
    public event EventHandler<EventArgs>? SampleEvent;

    public virtual void RaiseEvent() => SampleEvent?.Invoke(this, new EventArgs());
}

public class Subscriber : IWeakEventListener
{
    public void Receive(object? sender, EventArgs e)
    {
        Console.WriteLine("触发事件");
    }

    //通过该方法来处理弱事件管理器推送过来的订阅信息
    public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
    {
        Receive(sender, e as EventArgs);
        return true;
    }
}

public class BaseWeakEventManager : WeakEventManager
{
    public static void AddListener(object source, IWeakEventListener listener)
    {
        CurrentManager.ProtectedAddListener(source, listener);
    }

    public static void RemoveListener(object source, IWeakEventListener listener)
    {
        CurrentManager.ProtectedRemoveListener(source, listener);
    }

    protected override void StartListening(object _source)
    {
        if (_source is Publisher _publisher)
        {
            _publisher.SampleEvent += DeliverEvent;
        }
    }

    protected override void StopListening(object _source)
    {
        if (_source is Publisher _publisher)
        {
            _publisher.SampleEvent -= DeliverEvent;
        }
    }

    public static BaseWeakEventManager CurrentManager
    {
        get
        {
            //从现有管理器中获取默认管理器对象
            if (GetCurrentManager(typeof(BaseWeakEventManager)) is not BaseWeakEventManager _manager)
            {
                _manager = new BaseWeakEventManager();

                //将新建的管理器对象设置为当前类型默认管理器
                SetCurrentManager(typeof(BaseWeakEventManager), _manager);
            }
            return _manager;
        }
    }
}